package com.ys.controller.web.account;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.config.MenuId;
import com.ys.entity.account.TcwNeedPayAccount;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.W;

/**
 * 应付账户管理
 */
@Controller
@RequestMapping("/web/account/tcwNeedPayAccount")
public class WebTcwNeedPayAccountController {

	@Autowired
	private CommonApiService<TcwNeedPayAccount> commonApiService;
	
	/*
	 * 新增
	 */
	@RequiresPermissions("tcwNeedPayAccount:add")
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response){
		try {
			TcwNeedPayAccount entity = new TcwNeedPayAccount();
			entity.setCode(commonApiService.getCommonNextUkey(MenuId.TCW_NeedPayAccount, "Code"))
				.setStatus(1);
			return commonApiService.toAdd(model, entity, MenuId.TCW_NeedPayAccount, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}

    /*
     * 编辑
     */
    @GetMapping("/toEdit")
    public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response, Long id) {
    	
    	Map<String, Object> extraParam = new TcwNeedPayAccount().setId(id)
    			
    			.addLeftJoin("TCW_PartnerBankInfo B ON B.Vid = A.PartnerBankInfoVid")
    			.addField("B.Vid partnerBankInfoVid")
    			.addField("B.Vyhzhmc partnerBankInfoName")
    			.addField("B.Vyhzh partnerBankInfoVyhzh")
    			.addField("B.Vkhh partnerBankInfoVkhh")
    			.addField("B.PartnerId partnerId")
    			.addField("B.PartnerName partnerName")
    			
    			.addLeftJoin("THR_OperateCompanyApply C ON C.Vgsbm = A.Vgsbm")
    			.addField("C.Vgsjc vgsjc")
    			
    			.addLeftJoin("TS_UserChange C1 ON C1.Id = C.OperatorChangeId")
    			.addField("C1.UserId operatorUserId")
    			.addField("C1.DeptId operatorOrgid")
    			
    			.addLeftJoin("TB_CompanyInfo D ON D.Vid = A.CompanyVid")
    			.addField("D.Vname companyVname")
    			
    			.clearFieldsSource()
    			
    			.queryFirstMap();
    	

		try {
			return commonApiService.toEdit(model, id, new TcwNeedPayAccount(), MenuId.TCW_NeedPayAccount, extraParam, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
    }
}






